package com.kaka.service.serviceimpl;

import com.kaka.dao.StudentDao;
import com.kaka.dao.TeacherDao;
import com.kaka.dao.daoimpl.StudentDaoImpl;
import com.kaka.dao.daoimpl.TeacherDaoImpl;
import com.kaka.bean.Student;
import com.kaka.bean.Teacher;
import com.kaka.service.AdminService;
import com.kaka.util.SMSUtil;

public class AdminServiceImpl implements AdminService {

    private final StudentDao studentDao = new StudentDaoImpl();
    private final TeacherDao teacherDao = new TeacherDaoImpl();

    @Override
    public void insertNewStudent(String username, String password, String name) {
        SMSUtil.check(studentDao.insertNewStudent(new Student(username, password, name)));
    }

    @Override
    public void deleteStudent(int sid) {
        SMSUtil.check(studentDao.deleteBySid(sid));
    }

    @Override
    public void adminUpdateStudentPassword(int sid, String newPassword) {
        SMSUtil.check(studentDao.updatePasswordBySid(sid, newPassword));
    }

    @Override
    public void insertNewTeacher(String username, String password, String name) {
        SMSUtil.check(teacherDao.insertNewTeacher(new Teacher(username, password, name)));
    }

    @Override
    public void deleteTeacher(int tid) {
        SMSUtil.check(teacherDao.deleteByTid(tid));
    }

    @Override
    public void adminUpdateTeacherPassword(int tid, String newPassword) {
        SMSUtil.check(teacherDao.updatePasswordByTid(tid, newPassword));
    }
}
